'use strict';
const dbHelper = require("db-helper")
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('获取系统配置 : ', event)
	let {key} = event;
	try{
		let query = {};
		if (key) {
			query.key = key;
		}
		console.log("query", query);
		let configs = await dbHelper.getList("t3ds-system-config", query);
		if (key && configs.length === 0) {
			return {
				code: 500,
				msg: `不存在key=${key}的配置`
			}
		}
		let config = {};
		configs.forEach(item => {
			config[item.key] = item.value;
		})
		return {
			code: 200,
			result: config
		}
	}catch(e){
		return {
			code: 500,
			msg: e.message
		}
	}
};
